import commApi from '@/api/ve'
import api from '@/api/testDriver'
import { orgApis } from '@/api/vesalesapi'

// 车型车系... 有联动数据 有禁用联动
const ModelOptions = (isMust = false,
  span = 6,
  isRequire = false) =>
  [
    {
      compKey: 'carSeries',
      labelName: '车系名称：',
      codeField: 'carSeriesId',
      textField: 'carSeriesCn',
      oFields: 'carSeriesId,carSeriesCn',
      customObj: { api: orgApis.listOfCarSeries, selectType: '1' },
      component: () => import('@/components/org/commonSelect'),
      isMust: true,
      isRequire: true,
      span
    },
    {
      compKey: 'carConfig',
      labelName: '基础车型名称：',
      codeField: 'carConfigId',
      textField: 'carConfigCn',
      disabled: true,
      component: () => import('@/components/org/commonSelect'),
      oFields: 'carConfigId,carConfigCn',
      parentFileds: 'value:carSeriesId,disabled:carSeriesId-carConfigId--false',
      customObj: {
        listQuery: { carSeriesId: '' },
        api: orgApis.listOfCarModel, selectType: '1'
      },
      isMust: true,
      isRequire: true,
      span
    },
    {
      compKey: 'optionalPag',
      labelName: '选装包：',
      codeField: 'optionalPagId',
      textField: 'optionalPagName',
      disabled: true,
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId|carSeriesId,disabled:carConfigId-optionalPagId--false',
      oFields: 'optionalPagId,optionalPagName',
      customObj: {
        listQuery: {
          carConfigId: '', carSeriesId: ''
        },
        api: orgApis.listOfPackage, selectType: '1'
      },
      type: 'dropdownList',
      isMust: true,
      isRequire: true,
      span
    },
    {
      compKey: 'carColor',
      labelName: '车身颜色：',
      codeField: 'carColorId',
      textField: 'carColorName',
      disabled: true,
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId|carSeriesId|optionalPagId,disabled:optionalPagId-carColorId--false',
      oFields: 'carColorId,carColorName',
      customObj: {
        listQuery: {
          carConfigId: '', carSeriesId: '', optionalPagId: ''
        },
        api: orgApis.listOfCarColor, selectType: '1'
      },
      type: 'dropdownList',
      isMust: true,
      isRequire: true,
      span
    },
    {
      compKey: 'carIncolor',
      labelName: '内饰颜色：',
      codeField: 'carIncolorId',
      textField: 'carIncolorName',
      disabled: true,
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId|carSeriesId|optionalPagId,disabled:optionalPagId-carIncolorId--false',
      oFields: 'carIncolorId,carIncolorName',
      customObj: {
        listQuery: {
          carConfigId: '', carSeriesId: '', optionalPagId: ''
        },
        api: orgApis.listOfCarInterior, selectType: '1'
      },
      type: 'dropdownList',
      isMust: true,
      isRequire: true,
      span
    }
  ]

// 车型车系... 有联动数据 没有禁用联动效果
const ModelOptionsNotDisabled = (isMust = false,
  span = 6,
  isRequire = false) =>
  [
    {
      compKey: 'carSeries',
      labelName: '车系：',
      codeField: 'carSeriesId',
      textField: 'carSeriesCn',
      oFields: 'carSeriesId,carSeriesCn',
      customObj: { api: commApi.vehicleQuery, selectType: '1' },
      component: () => import('@/components/org/commonSelect'),
      isRequire,
      isMust,
      span
    },
    {
      compKey: 'carConfig',
      labelName: '基础车型：',
      codeField: 'carConfigId',
      textField: 'carConfigCn',
      component: () => import('@/components/org/commonSelect'),
      oFields: 'carConfigId,carConfigCn',
      parentFileds: 'value:carSeriesId',
      customObj: {
        listQuery: { carSeriesId: '' },
        api: commApi.ModelQuery, selectType: '1'
      },
      isRequire,
      isMust,
      span
    },
    {
      compKey: 'optionalPag',
      labelName: '选装包：',
      codeField: 'optionalPagId',
      textField: 'optionalPagName',
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId',
      oFields: 'optionalPagId,optionalPagName',
      customObj: {
        listQuery: {
          carConfigId: ''
        },
        api: commApi.queryPackByModel, selectType: '1'
      },
      type: 'inputText',
      isRequire,
      isMust,
      span
    },
    {
      compKey: 'carColor',
      labelName: '车身颜色：',
      codeField: 'carColorId',
      textField: 'carColorName',
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId|optionalPagId',
      oFields: 'carColorId,carColorName',
      customObj: {
        listQuery: {
          carConfigId: '',
          optionalPagId: ''
        },
        api: commApi.queryBodyColorByModel, selectType: '1'
      },
      type: 'inputText',
      isRequire,
      isMust,
      span
    },
    {
      compKey: 'carIncolor',
      labelName: '内饰颜色：',
      codeField: 'carIncolorId',
      textField: 'carIncolorName',
      component: () => import('@/components/org/commonSelect'),
      parentFileds: 'value:carConfigId|optionalPagId',
      oFields: 'carIncolorId,carIncolorName',
      customObj: {
        listQuery: {
          carConfigId: '',
          optionalPagId: ''
        },
        api: commApi.queryInnerColorByModel, selectType: '1'
      },
      type: 'inputText',
      isRequire,
      isMust,
      span
    }
  ]

// 车型车系... 无联动
const ModelOptionsUnrelated = () =>
  [
    {
      compKey: 'carSeries',
      labelName: '车系：',
      codeField: 'carSeriesId',
      component: () => import('@/components/org/commonSelect'),
      type: 'dropdownList',
      isMul: false,
      isMust: false,
      oFields: 'carSeriesId,carSeriesCn',
      customObj: {
        api: orgApis.listOfCarSeries
      }
    },
    {
      compKey: 'carConfig',
      labelName: '基础车型：',
      codeField: 'carConfigId',
      textField: 'carConfigCn',
      component: () => import('@/components/org/commonSelect'),
      type: 'dropdownList',
      isMul: false,
      isMust: false,
      oFields: 'carConfigId,carConfigCn',
      customObj: {
        api: orgApis.listOfCarModel
      }
    },
    {
      compKey: 'optionalPag',
      labelName: '选装包：',
      codeField: 'optionalPagId',
      textField: 'optionalPagName',
      component: () => import('@/components/org/commonSelect'),
      type: 'dropdownList',
      isMul: false,
      isMust: false,
      oFields: 'optionalPagId,optionalPagName',
      customObj: {
        api: orgApis.listOfPackage
      }
    },
    {
      compKey: 'carColor',
      labelName: '车身颜色：',
      codeField: 'carColorId',
      textField: 'carColorCode',
      component: () => import('@/components/org/commonSelect'),
      oFields: 'carColorId,carColorName',
      type: 'dropdownList',
      isMul: false,
      isMust: false,
      customObj: {
        api: orgApis.listOfCarColor
      }
    },
    {
      compKey: 'carIncolor',
      labelName: '内饰颜色：',
      codeField: 'carIncolorId',
      textField: 'carIncolorName',
      component: () => import('@/components/org/commonSelect'),
      oFields: 'carIncolorId,carIncolorName',
      type: 'dropdownList',
      isMul: false,
      isMust: false,
      customObj: {
        api: orgApis.listOfCarInterior
      }
    }
  ]

// 试驾车管理中的公共 字段
const frontFields = (num = 0) => {
  if (num === 1) {
    const data = type()
    data[0].isShow = false
    data[4].isMust = true
    return data
  } else if (num === 2) {
    const data = type()
    data[5].isShow = true
    return data
  } else {
    return type()
  }
}
const type = (isMust = true, span = 6, isShow = true) => [
  {
    compKey: 'insaleOrderStatus',
    labelName: '订单状态：',
    codeField: 'insaleOrderStatus',
    component: () => import('@/components/org/commonSelect'),
    lookuptype: 'VE1003',
    isMust,
    span,
    isShow
  },
  {
    compKey: 'saleOrderCode',
    labelName: '订单编号：',
    codeField: 'saleOrderCode',
    component: () => import('@/components/org/commonInput'),
    type: 'dropdownList',
    isMust,
    span
  },
  {
    compKey: 'insaleOrderCode',
    labelName: '试驾车单号：',
    codeField: 'insaleOrderCode',
    component: () => import('@/components/org/commonInput'),
    type: 'dropdownList',
    isMust,
    span
  },
  {
    compKey: 'deliveryDlrId',
    labelName: '交付门店：',
    codeField: 'deliveryDlrId',
    component: () => import('@/components/org/commonSelect'),
    oFields: 'deliveryDlrId,deliveryDlrShortName',
    customObj: {
      api: { APIUrl: api.QueryCenterByList.APIUrl },
      listQuery: { cityId: '' }
    },
    type: 'dropdownList',
    isMust: true,
    span
  },
  {
    compKey: 'tyId',
    labelName: '体验中心：',
    codeField: 'dlrId',
    component: () => import('@/components/org/commonSelect'),
    customObj: {
      listQuery: { cityId: '', dlrShortName: '', experienceDlrCode: '' },
      api: commApi.ListOfExperience, selectType: '1'
    },
    oFields: 'dlrId,dlrShortName',
    type: 'dropdownList',
    isMust: false,
    span
  },
  {
    compKey: 'carHouseName',
    labelName: '仓库名称：',
    codeField: 'carStockHouseId',
    component: () => import('@/components/org/commonSelect'),
    customObj: {
      listQuery: {
        warehouseId: '1'
      },
      api: commApi.ListOfCityWarehouse,
      selectType: '1'
    },
    oFields: 'stockId,stockName',
    type: 'dropdownList',
    isMust: false,
    isShow: false,
    span
  },
  {
    compKey: 'salePlanCode',
    labelName: '销售计划号：',
    codeField: 'salePlanCode',
    component: () => import('@/components/org/commonInput'),
    type: 'dropdownList',
    isMust: false,
    span
  },
  {
    compKey: 'vin',
    labelName: 'VIN码：',
    codeField: 'vin',
    component: () => import('@/components/org/commonInput'),
    type: 'dropdownList',
    isMust: false,
    span
  }
]

// 车型 车系 内饰颜色 车身颜色 选装包 表格展示
const ModelOptionsTableCol = () =>
  [
    {
      prop: 'carSeriesCn',
      label: '车系'
    },
    {
      prop: 'carConfigCn',
      label: '基础车型'
    },
    {
      prop: 'optionalPagName',
      label: '选装包'
    },
    {
      prop: 'carColorName',
      label: '车身颜色'
    },
    {
      prop: 'carIncolorName',
      label: '内饰颜色'
    }
  ]

const deliveryCityAndDlr = (isMust = false,
  span = 6,
  isRequire = false) =>
  [
    {
      compKey: 'deliveryCity',
      labelName: '交付城市：',
      codeField: 'deliveryCityId',
      textField: 'deliverycityText',
      oFields: 'cityCode,cityName',
      customObj: {
        api: { APIUrl: api.cityList.APIUrl },
        listQuery: { provinceId: '' }
      },
      component: () => import('@/components/org/commonSelect'),
      isRequire,
      isMust,
      span
    },
    {
      compKey: 'deliveryDlr',
      labelName: '交付门店：',
      codeField: 'deliveryDlrId',
      textField: 'deliveryCenterText',
      oFields: 'deliveryDlrId,deliveryDlrFullName',
      parentFileds: 'value:cityId-deliveryCityName',
      customObj: {
        api: { APIUrl: api.QueryCenterByList.APIUrl },
        listQuery: { cityId: '' }
      },
      component: () => import('@/components/org/commonSelect'),
      isRequire,
      isMust,
      span
    }
  ]

export default {
  ModelOptions,
  ModelOptionsNotDisabled,
  ModelOptionsUnrelated,
  ModelOptionsTableCol,
  frontFields,
  deliveryCityAndDlr
}
